//
//  AnimationTimingBootcamp.swift
//  FCSwiftUI
//
//  Created by 冯宣超 on 2023/2/22.
//

import SwiftUI

struct AnimationTimingBootcamp: View {
    
    @State var isAnimating: Bool = false
    let timing: Double = 10.0

    var body: some View {
        VStack {
            Button("Button") {
                withAnimation(Animation.default.repeatCount(5, autoreverses: true)) {
                    isAnimating.toggle()
                }
            }
            
            RoundedRectangle(cornerRadius: 20.0)
                .frame(width: isAnimating ? 350 : 50, height: 100)
                .animation(Animation.spring(response: 0.5, dampingFraction: 0.7, blendDuration: 1.0), value: isAnimating)
            
//            RoundedRectangle(cornerRadius: 20.0)
//                .frame(width: isAnimating ? 350 : 50, height: 100)
//                .animation(Animation.linear(duration: timing), value: isAnimating)
//
//            RoundedRectangle(cornerRadius: 20.0)
//                .frame(width: isAnimating ? 350 : 50, height: 100)
//                .animation(Animation.easeIn(duration: timing), value: isAnimating)
//
//            RoundedRectangle(cornerRadius: 20.0)
//                .frame(width: isAnimating ? 350 : 50, height: 100)
//                .animation(Animation.easeInOut(duration: timing), value: isAnimating)
//
//            RoundedRectangle(cornerRadius: 20.0)
//                .frame(width: isAnimating ? 350 : 50, height: 100)
//                .animation(Animation.easeOut(duration: timing), value: isAnimating)
        }
    }
}

struct AnimationTimingBootcamp_Previews: PreviewProvider {
    static var previews: some View {
        AnimationTimingBootcamp()
    }
}
